package com.water.component.nacos.config;

import com.alibaba.nacos.api.config.listener.Listener;
import lombok.extern.slf4j.Slf4j;

import java.util.Properties;
import java.util.concurrent.Executor;

/**
 * packageName com.water.component.nacos.config
 *
 * @author
 * @className NacosListener(处以class为网)
 * @date 2025/3/13
 * @description T0D0
 */
@Slf4j
public class NacosListener implements Listener {
    //nacos 配置ID
    private String dataId;

    public NacosListener(String dataId){
        this.dataId = dataId;
    }

    @Override
    public Executor getExecutor() {
        return null;
    }

    @Override
    public void receiveConfigInfo(String configInfo) {
        log.debug("nacos receiveConfigInfo: {}", configInfo);
        Properties newProperties = new Properties();
        // yaml转换properties
        NacosConfigLoader.parseYamlToProperties(configInfo, newProperties);
        // 替换旧properties
        NacosConfigLoader.megerProperties(this.dataId, newProperties);
        // 刷新缓存
        NacosConfigLoader.refreshCache();
    }
}
